import { cloneDeep, merge } from "lodash"
import {
    GET_PROJECT,
    CHANGE_POINT_INDEX
} from "../actions"

// 建议稍后把考核人，也迁移到此处
const initialState = {
    nowProject: 0, // 现在是哪一个项目
    nowProjectPoint: [ // 该项目的考核点      （可能包含考核人,以及考核人其他信息）
        {
            name: "输出能力",
            pointMax: 20,
            pointMin: 10,
            person: [{
                name: "德莱文",
                point: [99, 22, 33, 44]
            }, {
                name: "拉克斯",
                point: [33, 22, 13, 44]
            }]
        }, {
            name: "团战能力",
            pointMax: 20,
            pointMin: 10,
            person: [{
                name: "凯瑟琳",
                point: [11, 22, 33, 24]
            }, {
                name: "皮尔斯",
                point: [33, 22, 22, 44]
            }]
        }, {
            name: "打野能力",
            pointMax: 20,
            pointMin: 10,
            person: [{
                name: "李青",
                point: [99, 22, 13, 44]
            }, {
                name: "吉格斯",
                point: [43, 22, 13, 44]
            }]
        }
    ],
    pointIndex: 0
}

// 默认参数值，是避免数据没有的时候浏览器报错
const handlers = {
    [GET_PROJECT]: (state, data = { content: [] }) => {
        return merge(state, { nowProject: data })
    },
    [CHANGE_POINT_INDEX]: (state, data = { content: [] }) => {
        const newState = cloneDeep(state);
        // newState.pointIndex = data;
        return merge(newState, { pointIndex: data });
    }
}

export default (state = initialState, action) => {
    const { type, data } = action
    if (!handlers[type]) {
        return state
    }
    return handlers[type](state, data)
}
